$(function(){
    showUploaderListInfo();
    function showUploaderListInfo(){
        layui.use(['table','form','util'], function(){
            var table = layui.table;
            var form = layui.form;

            // 数据表格渲染：信息页面
            table.render({
                elem: '#uploaderInfoList'
                ,id:'uploader'
                ,url:'/Uploader/findAll'
                ,height:390
                ,cellMinWidth: 80//全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,request:{
                    pageName: 'pn' //页码的参数名称，默认：page
                    ,limitName: 'limit' //每页数据量的参数名，默认：limit
                }

                ,parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.list, //解析数据列表
                    }
                }
                ,cols: [[
                    {field:'id',width:80,title: '序号',sort:true,fixed:'left',align:'center'}
                    ,{field:'hg_id',width:120,title: '护工ID',align:'center'}
                    ,{field:'hg_name',width:120, title: '护工姓名',align:'center'}
                    ,{field:'lr_id',width:120, title: '老人医保卡',align:'center'}
                    ,{field:'lr_name', width:120,title: '老人姓名',align:'center'}
                    ,{field:'organization_name', width:200,title: '所属机构',align:'center'}
                    ,{field:'uploadTime',width:200, title: '上传时间',align:'center',sort:true,templet : "<div>{{layui.util.toDateString(d.uploadTime, 'yyyy年MM月dd日')}}</div>"}
                    ,{fixed:'right',align:'center',toolbar: '#Del', width:170,title:'操作'}
                ]]
                ,page:true
            });

            // 搜索功能
            var $ = layui.$, active = {
                // 信息页面-搜索功能
                reload1: function(){
                    var lr_id = $('#lr_id');
                    var lr_name = $('#lr_name');
                    var hg_name=$('#hg_name');
                    console.log("[搜索的内容是:]"+lr_id.val()+lr_name.val()+hg_name.val());
                    //执行重载
                    table.reload('uploader', {
                        url: '/Uploader/findAll',
                        method:'post',
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            lr_id: lr_id.val(),
                            lr_name:lr_name.val(),
                            hg_name:hg_name.val(),
                        }
                    }, 'data');
                }
            }
            $('.SearchLoadSign .searchBtn').on('click', function () {
                console.log("触发按键");
                var type = $(this).data('type');
                console.log("type:"+type);
                active[type] ? active[type].call(this) : '';
                console.log("结束");
            });

            table.on('tool(uploader)', function(obj){
                var data = obj.data;
                console.log("[data:]",data);
                if(obj.event === 'del'){
                    layer.confirm('是否确定删除？', function(index){
                        $.ajax({
                            url:'/Uploader/deleteById',
                            method:'post',
                            data:{id:data.id},
                            success:function(){
                                console.log("[删除成功~]");
                                layer.msg("删除成功！")
                                obj.del();
                                layer.close(index);
                            },
                            error:function(){
                                layer.msg("删除信息出错")
                            }
                        })
                    });
                }
            });

        });
    }
});